//
//  MarriageProductCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/20.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "MarriageProductCell.h"

@implementation MarriageProductCell

- (void)awakeFromNib {
    [super awakeFromNib];

    self.priceLab.userInteractionEnabled = YES;
    [self.priceLab addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {

        if (self.MarriageProductLoginBlock) {
            self.MarriageProductLoginBlock();
        }
    }];
}

- (void)fillCellWithModel:(CommonPackageModel *)model {
    
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.fangUrl]  placeholderImage:[UIImage imageNamed:@"placeholder"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        
        if (image) {
            if (cacheType != SDImageCacheTypeMemory) {
                [UIView transitionWithView:self.mainImageView duration:0.61 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
                    [self.mainImageView setImage:image];
                    self.mainImageView.alpha = 1.0;
                } completion:nil];
            } else {
                self.mainImageView.alpha = 1.0;
                [self.mainImageView setImage:image];
            }
        }
        
    }];
    
    self.mainTitle.text = model.goodsName;
    
//    if ([TTUserModel sharedObject].token.length > 0) {
        self.priceLab.text = [NSString stringWithFormat:@"¥%@",[Utilities changeDoubleToString:model.goodsActivePrice]];
//    } else {
//        self.priceLab.text = @"登录后查看补贴价";
//    }
    
    self.viewCountLab.text = [NSString stringWithFormat:@"%ld",(long)model.goodsClickCount];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self pp_clipCorners:UIRectCornerAllCorners radius:6];
    });
    
}

+ (CGFloat)calculateHeightWithWidth:(CGFloat)collectionWeidth {

    CGFloat height = collectionWeidth/2 + 70;
    return height;
}

+ (CGFloat)calculateHeightModel:(CommonPackageModel *)model AndWidth:(CGFloat)width {
    
    CGFloat imgH = (width-40)/2;
    CGFloat distance = 10;
    CGFloat titleH = [Utilities getStringHeightWithText:model.goodsName font:[UIFont systemFontOfSize:13 weight:UIFontWeightBold] viewWidth:(imgH - 8)];
    CGFloat priceH = 40;
    return imgH + distance + titleH + priceH;
}

@end
